package logic

import (
	"context"
	"shell/houserpc/houserpc"

	"shell/api/internal/svc"
	"shell/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForgetPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewForgetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgetPasswordLogic {
	return &ForgetPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ForgetPasswordLogic) ForgetPassword(req *types.ForgetPasswordLoginRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	password, err := l.svcCtx.HouseRpc.ForgetPassword(l.ctx, &houserpc.ForgetPasswordRequest{
		Mobile:      req.Mobile,
		SendSmsCode: req.SendSmsCode,
		Password:    req.Password,
		NewPassword: req.NewPassword,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改密码成功",
		Data:    password,
	}, nil
}
